#include "view_time_1.h"
#include "view_time_1.inc"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font_mngr.h"
//#include "view_common.h"
#include "app_trace.h"
void view_time_1_display(void)
{
    bool is_ble_connected = false;
    int battery_percent = 0;
    int week_index = 0;
    int month = 0;
    int day = 0;
    bool is_charge = false;
    int hour = 0;
    int minute = 0;
    int show_index = 0;

    is_ble_connected = disp_ctrl.com_data.u_temp[1];
    battery_percent = disp_ctrl.com_data.u_temp[3];
    week_index = disp_ctrl.com_data.u_temp[9] - 1;
    month = disp_ctrl.com_data.u_temp[4];
    day = disp_ctrl.com_data.u_temp[5];
    is_charge = disp_ctrl.com_data.u_temp[2];
    hour = disp_ctrl.com_data.u_temp[6];
    minute = disp_ctrl.com_data.u_temp[7];
    show_index = disp_ctrl.auto_refresh_count;

    draw_on_chip_image(0, 0, bmp_time_1_back);
    if (is_ble_connected)
    {
        draw_on_chip_image(5, 4, bmp_ble_connect);
    }
    else
    {
        draw_on_chip_image(5, 2, bmp_ble_disconnect);
    }
    int x = 63;
    int y = 3;
    draw_on_chip_image(x, y, bmp_battery);
    x += 2;
    y += 2;
    if (is_charge && show_index % 2 == 0)
    {
        // no thing
    }
    else
    {
        int height = 7 * battery_percent / 100;
        draw_rectangle(x, y, x + height - 1, y + 2 - 1, RGB565_COLOR_WHITE);
    }
    {
        // bmp_num_13x19_TAB
        int num_width = 13;
        int num_height = 19;
        int num_interval = 1;
        int colon_width = 4;
        int colon_height = 12;
        int colon_interval = 1;
        int total_height = num_width * 4 + num_interval * 2 + colon_width + colon_interval * 2;
        x = (80 - total_height) / 2;
        y = 58;
        x = draw_on_chip_image_num_with_digits(hour, 2, x, y, bmp_num_13x19_TAB, num_width, num_interval, draw_type_normal);
        x += colon_interval;
        draw_on_chip_image(x, y + num_height - colon_height, bmp_time1_colon);
        x += colon_width + colon_interval;
        x = draw_on_chip_image_num_with_digits(minute, 2, x, y, bmp_num_13x19_TAB, num_width, num_interval, draw_type_normal);
    }
    {
        y = 88;
        int month_digits = get_num_digit(month);
        int week_interval = 4;
        int num_interval = 1;
        int slash_interval = 1;
        int slash_width = 6; // bmp_num_8x10_slash
        int num_width = 8;   // bmp_num_8x10_TAB
        int week_width = 0;
        const unsigned char *week_img = bmp_time_1_week_TAB[week_index];
        week_width = week_img[0];
        int total = week_width + week_interval + (month_digits + 2) * num_width + (month_digits - 1 + 1) * num_interval + slash_interval * 2 + slash_width;
        x = (80 - total) / 2;
        draw_on_chip_image(x, y, week_img);
        x += week_width + week_interval;
        x = draw_on_chip_image_num(month, x, y, bmp_num_8x10_TAB, num_width, num_interval, draw_type_normal);
        x += slash_interval;
        draw_on_chip_image(x, y - 1, bmp_num_8x10_slash);
        x += slash_interval + slash_width;
        x = draw_on_chip_image_num_with_digits(day, 2, x, y, bmp_num_8x10_TAB, num_width, num_interval, draw_type_normal);
    }
}
